package p2Greep;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class GrepMapper extends Mapper<LongWritable, Text, NullWritable,tokenBean> {
    private String mapRegex="null";

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line=value.toString();
        String[] fields=line.split(",");
        String uid=fields[0];
        String mid=fields[1];
        String cid=fields[2];
        String drate=fields[3];
        String rdate=fields[4];
        String date=fields[5];

        tokenBean valueOut=new tokenBean(uid,mid,cid,drate,rdate,date);

        //验证是否和用户传进来的正则表达式匹配，如果匹配则输出，从而起到过滤作用
        if(!(cid.matches(mapRegex))){
            context.write(NullWritable.get(),valueOut);
        }
    }
}
